<template>
  <div class="app-container">
    <el-radio-group
      v-model="tabPosition"
      style="margin-bottom: 10px"
      @change="tabPositionfun"
    >
      <el-radio-button label="正线">正线</el-radio-button>
      <el-radio-button label="站内">站内</el-radio-button>
    </el-radio-group>
    <div v-if="tabPosition == '正线'">
      <el-form :model="queryParams" ref="queryForm" :inline="true">
        <el-form-item label="">
          <el-select
            filterable
            clearable
            style="width: 140px"
            v-model="queryParams.railwayName"
            placeholder="线名"
          >
            <el-option
              v-for="dict in railwayNamearr"
              :label="dict.railwayName"
              :value="dict.railwayName"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="">
          <el-select
            filterable
            clearable
            style="width: 140px"
            v-model="queryParams.progressType"
            placeholder="上下行"
          >
            <el-option
              v-for="dict in progressTypearr"
              :label="dict.progressType"
              :value="dict.progressType"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="" class="formitemcla">
          <el-input
            v-model="queryParams.startMileageNumber"
            type="number"
            placeholder="起点里程"
            clearable
            style="width: 140px"
            @keyup.enter.native="handleQuery"
          >
            <template #suffix> km </template>
          </el-input>
        </el-form-item>
        <el-form-item label="~">
          <el-input
            v-model="queryParams.endMileageNumber"
            type="number"
            placeholder="终点里程"
            clearable
            style="width: 140px"
            @keyup.enter.native="handleQuery"
          >
            <template #suffix> km </template>
          </el-input>
        </el-form-item>
        <el-form-item label="">
          <el-select
            filterable
            clearable
            style="width: 140px"
            v-model="queryParams.datumType"
            placeholder="资料类型"
          >
            <el-option
              v-for="dict in datumTypeobj"
              :label="dict.datumType"
              :value="dict.datumType"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="">
          <el-input
            style="width: 140px"
            v-model="queryParams.datumName"
            placeholder="资料名称"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="handleQuery">搜索</el-button>
          <el-button type="primary" @click="congzhiQuery">重置</el-button>
          <el-button @click="handleAdd">上传</el-button>
        </el-form-item>
      </el-form>

      <el-table v-loading="loading" :data="datumList" height="56vh" border>
        <el-table-column type="index" width="55" label="序号" />
        <el-table-column label="线路" prop="railwayName" />
        <el-table-column label="上下行" prop="progressType" />
        <el-table-column label="起点里程" prop="startMileage" />
        <el-table-column label="终点里程" prop="endMileage" />
        <el-table-column label="资料名称" prop="datumName" />
        <el-table-column label="资料编号" prop="datumCode" />
        <el-table-column label="资料类型" prop="datumType" />
        <el-table-column label="涉及设备" prop="involveEquipment" />
        <el-table-column label="上传时间" prop="createTime" />
        <el-table-column label="上传人员" prop="uploadUser" />
        <el-table-column label="修改人员" prop="editUser" />
        <el-table-column label="备注" prop="remark" />
        <el-table-column min-width="120">
          <template #default="scope">
            <el-button link type="primary" @click="handleExport(scope.row)"
              >下载</el-button
            >
            <el-button link type="primary" @click="handleUpdate(scope.row)"
              >修改</el-button
            >
            <el-button link type="primary" @click="handleDelete(scope.row)"
              >删除</el-button
            >
          </template>
        </el-table-column>
      </el-table>
    </div>
    <div v-if="tabPosition == '站内'">
      <el-form :model="queryParams" ref="queryForm" :inline="true">
        <el-form-item label="">
          <el-select
            filterable
            clearable
            style="width: 140px"
            v-model="queryParams.railwayName"
            placeholder="线名"
          >
            <el-option
              v-for="dict in railwayNamearr"
              :label="dict.railwayName"
              :value="dict.railwayName"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="">
          <el-select
            filterable
            clearable
            style="width: 140px"
            v-model="queryParams.stationName"
            placeholder="车站名"
          >
            <el-option
              v-for="dict in stationNamearr"
              :label="dict.stationName"
              :value="dict.stationName"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="" class="formitemcla">
          <el-input
            v-model="queryParams.startMileageNumber"
            type="number"
            placeholder="起点里程"
            clearable
            style="width: 140px"
            @keyup.enter.native="handleQuery"
          >
            <template #suffix> km </template>
          </el-input>
        </el-form-item>
        <el-form-item label="~">
          <el-input
            v-model="queryParams.endMileageNumber"
            type="number"
            placeholder="终点里程"
            clearable
            style="width: 140px"
            @keyup.enter.native="handleQuery"
          >
            <template #suffix> km </template>
          </el-input>
        </el-form-item>
        <el-form-item label="">
          <el-select
            filterable
            clearable
            style="width: 140px"
            v-model="queryParams.datumType"
            placeholder="资料类型"
          >
            <el-option
              v-for="dict in datumTypeobj"
              :label="dict.datumType"
              :value="dict.datumType"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="">
          <el-input
            style="width: 140px"
            v-model="queryParams.datumName"
            placeholder="资料名称"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="handleQuery">搜索</el-button>
          <el-button type="primary" @click="congzhiQuery">重置</el-button>
          <el-button @click="handleAdd">上传</el-button>
        </el-form-item>
      </el-form>

      <el-table v-loading="loading" :data="datumList" height="56vh" border>
        <el-table-column type="index" width="55" label="序号" />
        <el-table-column label="线路" prop="railwayName" />
        <el-table-column label="车站名" prop="stationName" />
        <el-table-column label="股道名称" prop="trackCode" />
        <el-table-column label="起点里程" prop="startMileage" />
        <el-table-column label="终点里程" prop="endMileage" />
        <!-- <el-table-column label="起点里程(数字版)" prop="startMileageNumber" />
      <el-table-column label="终点里程(数字版)" prop="endMileageNumber" /> -->
        <el-table-column label="资料名称" prop="datumName" />
        <el-table-column label="资料编号" prop="datumCode" />
        <el-table-column label="涉及设备" prop="involveEquipment" />
        <el-table-column label="上传时间" prop="createTime" />
        <el-table-column label="上传人员" prop="uploadUser" />
        <el-table-column label="修改人员" prop="editUser" />
        <el-table-column label="备注" prop="remark" />
        <el-table-column min-width="120">
          <template #default="scope">
            <el-button link type="primary" @click="handleExport(scope.row)"
              >下载</el-button
            >
            <el-button link type="primary" @click="handleUpdate(scope.row)"
              >修改</el-button
            >
            <el-button link type="primary" @click="handleDelete(scope.row)"
              >删除</el-button
            >
          </template>
        </el-table-column>
      </el-table>
    </div>
    <!-- 添加或修改资料数据对话框 -->
    <el-dialog
      :title="title"
      v-model="open"
      width="1250px"
      append-to-body
      draggable
    >
      <el-form
        ref="form"
        :model="forma"
        :rules="rules"
        label-width="100px"
        :inline="true"
      >
        <el-form-item label="线名" prop="railwayId">
          <el-select
            filterable
            clearable
            style="width: 180px"
            v-model="forma.railwayId"
            placeholder="请选择"
          >
            <el-option
              v-for="dict in railwayNameobj"
              :label="dict.railwayName"
              :value="dict.id"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item
          v-if="tabPosition == '正线'"
          label="上下行"
          prop="progressTypeId"
        >
          <el-select
            filterable
            clearable
            style="width: 180px"
            v-model="forma.progressTypeId"
            placeholder="请选择"
          >
            <el-option
              v-for="dict in progressTypeobj"
              :label="dict.progressType"
              :value="dict.id"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item
          v-if="tabPosition == '站内'"
          label="车站名"
          prop="stationName"
        >
          <el-select
            filterable
            clearable
            style="width: 180px"
            v-model="forma.stationName"
            placeholder="请选择"
          >
            <el-option
              v-for="dict in stationNameobj"
              :label="dict.stationName"
              :value="dict.stationName"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="起点里程" prop="startMileageNumber">
          <el-input
            style="width: 180px"
            type="number"
            v-model="forma.startMileageNumber"
            placeholder="请输入起点里程"
          />
        </el-form-item>
        <el-form-item label="终点里程" prop="endMileageNumber">
          <el-input
            style="width: 180px"
            type="number"
            v-model="forma.endMileageNumber"
            placeholder="请输入终点里程"
          />
        </el-form-item>
        <el-form-item
          v-if="tabPosition == '站内'"
          label="股道名称"
          prop="trackCode"
        >
          <el-select
            filterable
            clearable
            style="width: 180px"
            v-model="forma.trackCode"
            placeholder="请输入"
          >
            <el-option
              v-for="dict in trackListobj"
              :label="dict.trackCode"
              :value="dict.trackCode"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="涉及设备" prop="involveEquipmentstr">
          <el-select
            filterable
            clearable
            style="width: 180px"
            collapse-tags
            :max-collapse-tags="1"
            v-model="forma.involveEquipmentstr"
            :data="forma"
            multiple
            placeholder="请选择"
          >
            <el-option
              v-for="dict in involveEquipmentobj"
              :label="dict.propertyName"
              :value="dict.propertyName"
            ></el-option>
          </el-select>
        </el-form-item>
      </el-form>
      <el-table
        v-loading="loading1"
        :data="datumqueryList"
        height="20vh"
        border
      >
        <el-table-column label="资料编号" prop="datumCode" min-width="80"
          ><template #default="scope"
            ><el-input
              :disabled="title == '共享资料修改'"
              v-model="scope.row.datumCode"
              placeholder="请输入" /></template
        ></el-table-column>
        <el-table-column label="资料名称" prop="datumName" min-width="100"
          ><template #default="scope"
            ><el-input
              v-model="scope.row.datumName"
              placeholder="请输入"
              disabled
              style="width: 100px"
            />
            <el-upload
              :file-list="scope.row.fileList"
              :before-upload="handleBeforeUpload"
              name="files"
              :show-file-list="false"
              :auto-upload="false"
              :on-change="onChange"
              class="upload-file-uploader"
              ref="fileUpload"
            >
              <!-- :limit="1" -->
              <div class="imgflex" @click="FileUploadfun(scope.row)">
                <img class="img1" src="@/assets/images/u2465.svg" />
                <img class="img2" src="@/assets/images/u2464.svg" />
              </div>
            </el-upload> </template
        ></el-table-column>
        <el-table-column label="资料类型" prop="datumType" min-width="80"
          ><template #default="scope">
            <el-input
              v-model="scope.row.datumType"
              placeholder="资料类型"
              disabled
            /> </template
        ></el-table-column>
        <el-table-column label="上传时间" prop="createTime" min-width="120"
          ><template #default="scope">
            <!-- <el-date-picker disabled style="width: 180px" v-model="scope.row.createTime" type="time" placeholder="标记时间" /> -->
            <el-date-picker
              disabled
              style="width: 180px"
              format="YYYY/MM/DD"
              value-format="YYYY/MM/DD"
              v-model="scope.row.createTime"
              type="datetime"
              placeholder="标记时间"
            /> </template
        ></el-table-column>
        <el-table-column label="上传人员" prop="uploadUser" min-width="80"
          ><template #default="scope"
            ><el-input
              disabled
              v-model="scope.row.uploadUser"
              placeholder="请输入" /></template
        ></el-table-column>
        <el-table-column
          v-if="title == '共享资料修改'"
          label="修改人员"
          prop="editUser"
          min-width="80"
          ><template #default="scope"
            ><el-input
              disabled
              v-model="scope.row.editUser"
              placeholder="请输入" /></template
        ></el-table-column>
        <el-table-column label="备注" prop="remark" min-width="80">
          <template #default="scope"
            ><el-input
              v-model="scope.row.remark"
              placeholder="请输入" /></template
        ></el-table-column>
        <el-table-column
          label="操作"
          prop=""
          min-width="80"
          v-if="title != '共享资料修改'"
        >
          <template #default="scope" class="buttontext">
            <el-button
              link
              type="primary"
              @click="temporaryDelete(scope.row, scope.$index)"
              >删除</el-button
            >
          </template>
        </el-table-column>
      </el-table>
      <div
        v-if="title != '共享资料修改'"
        class="addtablecalss"
        @click="addtablefun"
      >
        添加
      </div>

      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script setup name="curve">
import {
  insertDatumapi,
  editShareDatumapi,
  deleteManDatumByIdapi,
  selectManBasicRailwayListapi,
  selectManBasicUnitListapi,
  selectManBasicprogressTypeListapi,
  selectManBasicPropertyListapi,
  selectManBasicStationListapi,
  selectManDatumListapi,
  selectManStationFacilityTrackListapi,
} from "@/api/main/api.js";
import { reactive, ref, toRefs } from "vue";
defineExpose({ getList });
const emit = defineEmits(["parentCount"]);
const { proxy } = getCurrentInstance();
const loading = ref(true);
const title = ref("共享资料新增");
const open = ref(false);
const tabPosition = ref("正线");
const loading1 = ref(false);
const data = reactive({
  // 基础数据-单位数据表格数据
  datumList: [],
  // 查询参数
  queryParams: {
    pageNum: "1",
    pageSize: "10",
    railwayName: "",
    progressType: "",
    startMileageNumber: "",
    endMileageNumber: "",
    curveRadius: "",
    railwayId: "",
    progressTypeId: "",
    stationId: "",
    type: "正线",
    status: "共享",
  },
  datumTypeobj: [],
  involveEquipmentobj: [
    // { value: "钢轨", label: "钢轨" },
    // { value: "道岔", label: "道岔" },
    // { value: "轨枕", label: "轨枕" },
    // { value: "扣件", label: "扣件" },
  ],
  railwayNameobj: [],
  unitNameobj: [],
  progressTypeobj: [],
  // 表单参数
  forma: {},
  // 表单校验
  rules: {
    railwayId: [
      {
        required: true,
        message: "线路名称不能为空",
        trigger: ["blur", "change"],
      },
    ],
    progressTypeId: [
      {
        required: true,
        message: "上下行不能为空",
        trigger: ["blur", "change"],
      },
    ],
    startMileageNumber: [
      {
        required: true,
        message: "起点里程不能为空",
        trigger: ["blur", "change"],
      },
    ],
    endMileageNumber: [
      {
        required: true,
        message: "终点里程不能为空",
        trigger: ["blur", "change"],
      },
    ],
    involveEquipmentstr: [
      {
        required: true,
        message: "涉及设备不能为空",
        trigger: ["blur", "change"],
      },
    ],
    trackCode: [
      {
        required: true,
        message: "股道名称不能为空",
        trigger: ["blur", "change"],
      },
    ],
  },
  editobj: {},
  railwayNamearr: [],
  progressTypearr: [],
  propertyList: [],
  datumqueryList: [],
  datumqueryItemName: {},
  stationNamearr: [],
  stationNameobj: [],
  trackListobj: [],
});
const {
  trackListobj,
  stationNameobj,
  stationNamearr,
  datumqueryItemName,
  datumqueryList,
  involveEquipmentobj,
  propertyList,
  datumTypeobj,
  railwayNamearr,
  progressTypearr,
  queryParams,
  forma,
  rules,
  datumList,
  unitNameobj,
  railwayNameobj,
  editobj,
  progressTypeobj,
} = toRefs(data);

function tabPositionfun() {
  queryParams.value.type = tabPosition.value;
  getList();
}
function congzhiQuery() {
  // 查询参数
  queryParams.value = {
    railwayName: "",
    progressType: "",
    startMileageNumber: "",
    endMileageNumber: "",
    curveRadius: "",
    railwayId: "",
    progressTypeId: "",
    stationId: "",
    status: "共享",
  };
  queryParams.value.type = tabPosition.value;
  getList();
}
/** 查询基础数据-单位数据列表 */
const pageNumparent = ref(undefined);
const pageSizeparent = ref(undefined);
/** 查询列表 */
function getList(pageNum, pageSize) {
  loading.value = true;
  if (pageNum != undefined || pageSize != undefined) {
    pageNumparent.value = pageNum;
    pageSizeparent.value = pageSize;
    queryParams.value.pageNum = pageNum == undefined ? 1 : pageNum;
    queryParams.value.pageSize = pageSize == undefined ? 10 : pageSize;
  } else {
    queryParams.value.pageNum =
      pageNumparent.value == undefined ? "1" : pageNumparent.value;
    queryParams.value.pageSize =
      pageSizeparent.value == undefined ? "10" : pageSizeparent.value;
  }
  queryParams.value.railwayId = "";
  queryParams.value.progressTypeId = "";
  queryParams.value.stationId = "";
  for (let i = 0; i < datumList.value.length; i++) {
    if (queryParams.value.railwayName == datumList.value[i].railwayName) {
      queryParams.value.railwayId = datumList.value[i].railwayId;
    }
  }
  for (let i = 0; i < datumList.value.length; i++) {
    if (queryParams.value.progressType == datumList.value[i].progressType) {
      queryParams.value.progressTypeId = datumList.value[i].progressTypeId;
    }
  }
  for (let i = 0; i < datumList.value.length; i++) {
    if (queryParams.value.stationName == datumList.value[i].stationName) {
      queryParams.value.stationId = datumList.value[i].stationId;
    }
  }

  selectManDatumListapi(queryParams.value).then((res) => {
    if (res.code == 200) {
      datumList.value = res.data;
      loading.value = false;
      const xian = {};
      railwayNamearr.value = datumList.value.reduce((next, item) => {
        xian[item.railwayName] == undefined
          ? (xian[item.railwayName] = true & next.push(item))
          : "";
        return next;
      }, []);
      const hang = {};
      progressTypearr.value = datumList.value.reduce((next, item) => {
        hang[item.progressType] == undefined
          ? (hang[item.progressType] = true & next.push(item))
          : "";
        return next;
      }, []);
      const che = {};
      stationNamearr.value = datumList.value.reduce((next, item) => {
        che[item.stationName] == undefined
          ? (che[item.stationName] = true & next.push(item))
          : "";
        return next;
      }, []);
      const zilleix = {};
      datumTypeobj.value = datumList.value.reduce((next, item) => {
        zilleix[item.datumType] == undefined
          ? (zilleix[item.datumType] = true & next.push(item))
          : "";
        return next;
      }, []);
      emit("parentCount", res.count);
    }
  });
}
getList();
/** 查询基础数据-单位数据列表 */
function getList1() {
  selectManBasicRailwayListapi({ hasDelete: 0 }).then((res) => {
    if (res.code == 200) {
      railwayNameobj.value = res.data;
    }
  });
}
getList1();
/** 查询基础数据-线名数据列表 */
function getList2() {
  selectManBasicUnitListapi({ hasDelete: 0 }).then((res) => {
    if (res.code == 200) {
      unitNameobj.value = res.data;
    }
  });
}
getList2();
/** 查询基础数据-上下行数据列表 */
function getList3() {
  selectManBasicprogressTypeListapi({ hasDelete: 0 }).then((res) => {
    if (res.code == 200) {
      progressTypeobj.value = res.data;
    }
  });
}
getList3();
/** 查询基础数据-属性维护数据列表 */
function getList4() {
  selectManBasicPropertyListapi({ hasDelete: 0 }).then((res) => {
    if (res.code == 200) {
      propertyList.value = res.data;
      involveEquipmentobj.value = [];
      for (let i = 0; i < propertyList.value.length; i++) {
        if (propertyList.value[i].propertyType == "涉及设备") {
          involveEquipmentobj.value.push(propertyList.value[i]);
        }
      }
    }
  });
}
getList4();
/** 查询基础数据-车站数据列表 */
function getList5() {
  selectManBasicStationListapi({ hasDelete: 0 }).then((res) => {
    if (res.code == 200) {
      stationNameobj.value = res.data;
    }
  });
}
getList5();
/** 查询基础数据-股道数据列表 */
function getList6() {
  selectManStationFacilityTrackListapi({ hasDelete: 0 }).then((res) => {
    if (res.code == 200) {
      trackListobj.value = res.data;
    }
  });
}
getList6();
function handleExport(row) {
  let fileId = "";
  fileId = row.id;
  proxy.download1("/file/datumFile/downDatumFileById", fileId, row.datumName);
}
/** 删除按钮操作 */
function handleDelete(row) {
  proxy.$modal
    .confirm("是否确认删除")
    .then(function () {
      return deleteManDatumByIdapi([row.id]);
    })
    .then(() => {
      getList();
      proxy.$modal.msgSuccess("删除成功");
    })
    .catch(() => {});
}
// 取消按钮
function cancel() {
  open.value = false;
}
/** 搜索按钮操作 */
function handleQuery() {
  getList();
}
function clear() {
  forma.value = {
    railwayId: "",
    progressTypeId: "",
    railwayName: "",
    progressType: "",
    startMileageNumber: "",
    endMileageNumber: "",
    involveEquipmentstr: [],
    involveEquipment: "",
    stationId: "",
    trackId: "",
    trackCode: "",
    stationName: "",
  };
}
//添加表
function addtablefun() {
  console.log(datumqueryList.value);
  datumqueryList.value.unshift({
    datumCode: "",
    datumName: "",
    datumType: "",
    createTime: "",
    uploadUser: "",
    remark: "",
    editUser: "",
    fileList: [],
    status: 0,
  });
}
//删除表
function temporaryDelete(row, index) {
  datumqueryList.value.splice(index, 1);
}
/** 新增按钮操作 */
function handleAdd() {
  open.value = true;
  clear();
  title.value = "共享资料新增";
  datumqueryList.value = [];
}
/** 修改按钮操作 */
function handleUpdate(row) {
  if (row.involveEquipment != "") {
    row.involveEquipmentstr = row.involveEquipment.split(",");
  }
  title.value = "共享资料修改";
  datumqueryList.value = [];
  editobj.value = JSON.parse(JSON.stringify(row));
  forma.value = JSON.parse(JSON.stringify(row));
  datumqueryList.value = JSON.parse(JSON.stringify([row]));
  datumqueryList.value[0].fileList = [];
  open.value = true;
}
//上传文件改变时
function onChange(file, changeFileList) {
  for (let i = 0; i < datumList.value.length; i++) {
    if (file.name == datumList.value[i].datumName) {
      proxy.$modal.msgError("请勿上传重复文件");
      return false;
    }
  }
  console.log([file], changeFileList);
  datumqueryItemName.value.fileList = [file];
  datumqueryList.value.fileList = [file];
  let fileName = file.name.split(".");
  fileName = fileName[fileName.length - 1];
  datumqueryItemName.value.datumType = fileName;
  datumqueryItemName.value.datumName = file.name;

  const currentTime = new Date();
  const year = currentTime.getFullYear();
  const month = currentTime.getMonth() + 1; // 月份从0开始，因此需要加1
  const day = currentTime.getDate();
  // const hours = currentTime.getHours();
  // const minutes = currentTime.getMinutes();
  // const seconds = currentTime.getSeconds();
  let dataobj =
    year +
    "/" +
    (month < 10 ? "0" + month : month) +
    "/" +
    (day < 10 ? "0" + day : day);
  if (title.value == "共享资料修改") {
    datumqueryItemName.value.editUser = sessionStorage.getItem("username");
  } else {
    datumqueryItemName.value.createTime = dataobj;
    datumqueryItemName.value.uploadUser = sessionStorage.getItem("username");
  }
}
function FileUploadfun(row) {
  datumqueryItemName.value = row;
}

/** 提交按钮 */
function submitForm() {
  proxy.$refs["form"].validate((valid) => {
    if (valid) {
      for (let i = 0; i < stationNameobj.value.length; i++) {
        if (forma.value.stationName == stationNameobj.value[i].stationName) {
          forma.value.stationId = stationNameobj.value[i].id;
        }
      }
      for (let i = 0; i < trackListobj.value.length; i++) {
        if (forma.value.trackCode == trackListobj.value[i].trackCode) {
          forma.value.trackId = trackListobj.value[i].id;
        }
      }

      if (
        forma.value.involveEquipmentstr.length != 0 &&
        Array.isArray(forma.value.involveEquipmentstr)
      ) {
        forma.value.involveEquipment =
          forma.value.involveEquipmentstr.join(",");
      }
      if (forma.value.id != null) {
        const newforma = JSON.parse(JSON.stringify(forma.value));
        for (const key in editobj.value) {
          for (const keya in newforma) {
            if (
              key == keya &&
              editobj.value[key] == newforma[keya] &&
              key != "id"
            ) {
              Reflect.deleteProperty(newforma, keya);
            }
          }
        }
        if (newforma.startMileageNumber != undefined) {
          newforma.startMileageNumber =
            Math.round(newforma.startMileageNumber * 1000000) / 1000000;
        }
        if (newforma.endMileageNumber != undefined) {
          newforma.endMileageNumber =
            Math.round(newforma.endMileageNumber * 1000000) / 1000000;
        }

        let formData = new FormData();
        let arrayList = JSON.parse(JSON.stringify(datumqueryList.value));
        //传文件
        for (let i = 0; i < datumqueryList.value.length; i++) {
          console.log(datumqueryList.value[i].fileList);
          datumqueryList.value[i].fileList.forEach((file, index) => {
            if (editobj.value.datumName != file.name) {
              formData.append("file", file.raw);
            }
          });
        }
        //传字段
        for (let i = 0; i < arrayList.length; i++) {
          for (const keya in arrayList[i]) {
            if (
              arrayList[i][keya] == editobj.value[keya] &&
              keya != "id" &&
              keya != "datumPath"
            ) {
              Reflect.deleteProperty(arrayList[i], keya);
            }
          }
          delete arrayList[i].involveEquipmentstr;
          delete arrayList[i].fileList;
          arrayList[i].type = tabPosition.value;
        }
        for (let i = 0; i < arrayList.length; i++) {
          for (const key in newforma) {
            arrayList[i][key] = newforma[key];
          }
        }
        formData.append("datum", JSON.stringify(arrayList[0]));
        editShareDatumapi(formData).then((res) => {
          proxy.$modal.msgSuccess("修改成功");
          open.value = false;
          getList();
        });
      } else {
        forma.value.startMileageNumber =
          Math.round(forma.value.startMileageNumber * 1000000) / 1000000;
        forma.value.endMileageNumber =
          Math.round(forma.value.endMileageNumber * 1000000) / 1000000;

        let formData = new FormData();
        let arrayList = JSON.parse(JSON.stringify(datumqueryList.value));
        for (let i = 0; i < datumqueryList.value.length; i++) {
          if (datumqueryList.value[i].fileList.length == 0) {
            proxy.$modal.msgError("请选择上传文件");
            return;
          }
        }
        //传文件
        for (let i = 0; i < datumqueryList.value.length; i++) {
          datumqueryList.value[i].fileList.forEach((file, index) => {
            formData.append("files", file.raw);
          });
        }
        //传字段
        for (let i = 0; i < arrayList.length; i++) {
          delete arrayList[i].involveEquipmentstr;
          delete arrayList[i].fileList;
          arrayList[i].type = tabPosition.value;
          for (const key in forma.value) {
            arrayList[i][key] = forma.value[key];
          }
        }
        formData.append("datumList", JSON.stringify(arrayList));
        insertDatumapi(formData).then((response) => {
          proxy.$modal.msgSuccess("新增成功");
          open.value = false;
          getList();
        });
      }
    }
  });
}
</script>
<style scoped lang="scss">
.el-form--inline .el-form-item.formitemcla {
  margin-right: 5px !important;
}
.addtablecalss {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 30px;
  border-width: 1px;
  border-style: dashed;
  margin-bottom: 10px;
  cursor: pointer;
}
.imgflex {
  cursor: pointer;
  float: right;
  margin-top: 6px;
  width: 26px;
  height: 30px;
  display: flex;
  flex-direction: column;
  .img1 {
    width: 25px;
    height: 20px;
  }
  .img2 {
    width: 25px;
    height: 8px;
  }
}
.upload-file-uploader {
  float: right;
}
</style>
